<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style>
			.de{
				width: 200px;
				height: 200px;
				border: 1px solid green;
				position: relative;
				margin-left: 20px;
				float: left;
			}
		</style>
	</head>
	<body>
		<div id="demo" class="de"></div>
		<script>
			var x=document.getElementById("demo")
			function getLocation(){
				if(navigator.geolocation){
					/* 
					1.	获取地理信息成功之后的回调
					2.获取地理信息失败之后的回调
					3.获取当前地理信息的方式
					 */
					//navigator.geolocation.getCurrentPosition(success,error,option)
					navigator.geolocation.getCurrentPosition(showPosition,showError,{
						enableHighAccuracy:true,timeout:3000
					})
				}
				else{
					x.innerHTML="Geolocation is not supported by this browser"
				}
			}
			function showPosition(position){
				x.innerHTML="Latitude:"+position.coords.latitude+
					"<br />Longitude:"+position.coords.longitude;
			}
			function showError(error){
				switch(error.code){
					case error.PERMISSI0N_DENIED:
						x.innerHTML="User denied the"
						bareak;
					case error.POSITION_UNAVAILABLE:
						x.innerHTML="User denied the"
						bareak;
					case error.TIMEOUT:
						x.innerHTML="User denied the"
						bareak;
					case error.UNKNOWN_ERROR:
						x.innerHTML="User denied the"
						bareak;
				}
				
			}
			getLocation();
		</script>
	</body>
</html>